<!--页面主要内容-->
<main class="lyear-layout-content">
      
    <div class="container-fluid p-t-15">
      
      <div class="row">
        <div class="col-lg-12">
          <div class="card">
            <div class="card-toolbar d-flex flex-column flex-md-row">
              <div class="toolbar-btn-action">
                <!-- <a class="btn btn-primary m-r-5" href="#!"><i class="mdi mdi-plus"></i> 新增</a>
                <a class="btn btn-success m-r-5 ajax-post confirm" href="http://www.lyear.com/doc_test.php" target-form="ids"><i class="mdi mdi-check"></i> 启用</a>
                <a class="btn btn-warning m-r-5" href="#!"><i class="mdi mdi-block-helper"></i> 禁用</a> -->
                <a class="btn btn-danger dels"><i class="mdi mdi-window-close"></i> 批量删除</a>
              </div>
              
              <form class="search-bar ml-md-auto" method="get" action="#!" role="form">
                <input type="hidden" name="search_field" id="search-field" value="nickname" />
                <div class="input-group ml-md-auto">
                  <div class="input-group-prepend">
                    <button class="btn btn-default dropdown-toggle" type="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false" id="search-btn">用户名</button>
                    <div class="dropdown-menu" style="">
                      <a class="dropdown-item" href="javascript:void(0);" data-field="nickname">用户名</a>
                      <!-- <a class="dropdown-item" href="javascript:void(0);" data-field="createtime">日期</a> -->
                    </div>
                  </div>
                  <input type="text" class="form-control" name="keyword" placeholder="请输入名称">
                  <!-- <div class="form-group" hidden>
                    <div class="input-group" data-provide="datepicker">
                      <div class="input-group-prepend">
                        <span class="input-group-text">从</span>
                      </div>
                      <input type="text" class="form-control">
                      <div class="input-group-prepend input-group-append">
                        <span class="input-group-text">至</span>
                      </div>
                      <input type="text" class="form-control">
                    </div>
                    <button class="btn btn-default">搜索</button>
                  </div> -->
                </div>
              </form>
            </div>
            <div class="card-body">
              
              <div class="table-responsive">
                <table class="table table-bordered">
                  <thead>
                    <tr>
                      <th>
                        <div class="custom-control custom-checkbox">
                          <input type="checkbox" class="custom-control-input" id="check-all">
                          <label class="custom-control-label" for="check-all"></label>
                        </div>
                      </th>
                      <th>编号</th>
                      <th>消费用户</th>
                      <th>消费记录</th>
                      <th>消费状态</th>
                      <th>变化的积分</th>
                      <th>消费时间</th>
                      <th>操作</th>
                    </tr>
                  </thead>
                  <tbody>
                    {foreach $RecordList as $item}
                    <tr>
                      <td>
                        <div class="custom-control custom-checkbox">
                          <input type="checkbox" class="custom-control-input ids" name="ids[]" value="{$item.id}" id="ids-{$item.id}">
                          <label class="custom-control-label" for="ids-{$item.id}"></label>
                        </div>
                      </td>
                      <td>{++$num}</td>
                      <td>{$item.user.nickname}</td>
                      <td>{$item.content}</td>
                      <td>{$item.state_text}</td>
                      <td>{$item.point}</td>
                      <td>{$item.createtime|date="Y-m-d"}</td>
                      <td>
                        <div class="btn-group">
                          <!-- <a class="btn btn-xs btn-default" href="#!" title="" data-toggle="tooltip" data-original-title="编辑"><i class="mdi mdi-pencil"></i></a> -->
                          <a class="btn btn-xs btn-default del" data-id="{$item.id}" data-toggle="tooltip" data-original-title="删除"><i class="mdi mdi-window-close"></i></a>
                        </div>
                      </td>
                    </tr>
                    {/foreach}
                  </tbody>
                </table>
              </div>
              {$RecordList|raw}
     
            </div>
          </div>
        </div>
        
       
        
      </div>
      
    </div>
  
  </main>
  <!--End 页面主要内容-->
  <script>
    
    $(function () {


    // 搜索栏
    // $('.search-bar .dropdown-menu a').click(function() {
    //     let field = $(this).data('field') || '';
    //     // console.log(field);

    //     if(field == 'createtime')
    //     {
    //         $('.form-group').attr('hidden',false)
    //         $('input[name="keyword"]').attr('hidden',true)
    //     }else if(field == 'nickname')
    //     {
    //         $('.form-group').attr('hidden',true)
    //         $('input[name="keyword"]').attr('hidden',false)
    //     }
    // })

        $('.del').click(function () {
            $.confirm({
                title: '删除',
                content: '确认删除？',
                buttons: {
                    confirm: {
                        text: '确认',
                        btnClass: 'btn-info',
                        action: () => {
                            // 获取要删除的id
                            let recid = $(this).data('id')

                            $.ajax({
                                type: 'post',
                                url: `{:url('admin/record/del')}`,
                                data: {
                                    recid
                                },
                                dataType: 'json',
                                success: (result) => {
                                    if (result.code === 1) {
                                        $.notify({
                                            message: result.msg,
                                        }, {
                                            delay: 1000,
                                            type: 'success',
                                            onClose: function () {
                                                location.reload();
                                            }
                                        })
                                    } else {
                                        $.notify({
                                            message: result.msg,
                                        }, {
                                            delay: 1000,
                                            type: 'warning'
                                        })
                                    }
                                }
                            })
                        }
                    },
                    cancel: {
                        text: '取消',
                        btnClass: 'btn-danger'
                    }
                }
            })
        })

        $('.dels').click(function () {
            $.confirm({
                title: '批量删除',
                content: '确认批量删除？',
                buttons: {
                    confirm: {
                        text: '确认',
                        btnClass: 'btn-info',
                        action: () => {
                            // 获取要删除的id
                            let recid = GetId()

                            $.ajax({
                                type: 'post',
                                url: `{:url('admin/record/del')}`,
                                data: {
                                    recid
                                },
                                dataType: 'json',
                                success: (result) => {
                                    if (result.code === 1) {
                                        $.notify({
                                            message: result.msg,
                                        }, {
                                            delay: 1000,
                                            type: 'success',
                                            onClose: function () {
                                                location.reload()
                                            }
                                        })
                                    } else {
                                        $.notify({
                                            message: result.msg,
                                        }, {
                                            delay: 1000,
                                            type: 'warning'
                                        })
                                    }
                                }
                            })


                        }
                    },
                    cancel: {
                        text: '取消',
                        btnClass: 'btn-danger'
                    }
                }
            })

        })
    })
  </script>